import 'package:bilibili/page/profile_page.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/util/logger.dart';

class FadeInDemo2 extends StatefulWidget {
  const FadeInDemo2({super.key});

  @override
  State<StatefulWidget> createState() {
    return _FadeInDemo2State();
  }
}

class _FadeInDemo2State extends State<FadeInDemo2>
    with SingleTickerProviderStateMixin {
  late AnimationController controller;

  // late Animation<double> animation;
  bool expand = false;

  @override
  void initState() {
    super.initState();
    controller =
        AnimationController(duration: const Duration(seconds: 10), vsync: this)
          ..drive(CurveTween(curve: Curves.easeIn))
          ..addListener(() {
            logger.i(controller.value);
          });
    // animation = Tween<double>(begin: 0, end: 1).animate(controller);
  }

  @override
  Widget build(BuildContext context) {
    var padding = MediaQuery.of(context).padding;

    var logo = _buildLogo();

    return Scaffold(
      body: Column(
        children: [
          SizedBox(
            height: padding.top,
          ),
          InkWell(
            onTap: () {
              setState(() {
                expand = !expand;
                if (expand) {
                  controller.forward();
                } else {
                  controller.reverse();
                }
              });
            },
            child: Container(
                height: 20, width: double.infinity, color: Colors.greenAccent),
          ),
          AnimatedBuilder(
              animation: controller.view,
              child: logo,
              builder: (BuildContext context, Widget? child) {
                return Align(
                  heightFactor: controller.value,
                  child: Opacity(
                      opacity: controller.value,
                      child: Container(
                        alignment: Alignment.topLeft,
                        child: child,
                      )),
                );
              }),
          _buildOwner("迎娶白富美")
        ],
      ),
    );
  }

  Widget? _buildLogo() {
    return expand
        ? const FlutterLogo(
            size: 20,
          )
        : null;
  }
}

_buildOwner(String nikeName) {
  return Row(
    children: [
      Container(
        padding: const EdgeInsets.all(1),
        decoration: BoxDecoration(
          border: Border.all(width: 2.0, color: Colors.grey),
          borderRadius: const BorderRadius.all(Radius.circular(5)),
        ),
        child: const Text(
          "UP",
          style: TextStyle(color: Colors.grey, fontSize: 10),
        ),
      ),
      Padding(
        padding: const EdgeInsets.only(left: 5),
        child: Text(
          nikeName,
          style: const TextStyle(fontSize: 12, color: Colors.grey),
        ),
      )
    ],
  );
}

class FadeInApp2 extends StatelessWidget {
  const FadeInApp2({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: ProfilePage(),
    );
  }
}
